#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
    string reverseWords(string s) {
		int lastbegin = 0;		
		while(lastbegin<s.size())
		{
			while (s[lastbegin] == ' ')
				++lastbegin;
			if(lastbegin==s.size()-1)
				break;
			auto lastend=find(s.begin()+lastbegin,s.end(),' ');
			cout << lastbegin <<" "<< lastend-s.begin() << endl;
			reverse(s.begin() + lastbegin,  lastend);
			if(lastend==s.end())
				break;
			lastbegin = lastend - s.begin();		
		}
		return s;
    }
};
int main()
{
	Solution sol;
	auto ret = sol.reverseWords("Let's take LeetCode contest  ts ");
	cout << ret << endl;
}